<template>	
<!-- @click="gotoGoodsDetail($event,goods)" -->
		<view class="goods-item" >
			<view class="goods-item-left">
				<radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="clickHandler"></radio>
				<image :src="goods.goods_small_logo || defaultImg" mode=""></image>
			</view>
			<view class="goods-item-right">
				<view class="title">{{goods.goods_name}}</view>
				<view class="priceAndNum">
					<view class="price">￥&nbsp;{{goods.goods_price | tofixed}}</view>
					<view class="num">
						 <!-- 这里要写 :min="1" 把1解析为Number类型，否则会报错 -->
						<uni-number-box v-if="showNumberBox" :min="1" :value="goods.goods_count" @change="changeHandler" />
					</view>
				</view>
			</view>
		</view>
	
</template>

<script>
	export default {
		name:"my-goods",
		data() {
			return {				
				defaultImg: "https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png",
			};
		},
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNumberBox: {
				type: Boolean,
				default: false
			}
		},
		filters: {
			tofixed(num) {
				// 练习过滤器，保留两位小数
				return Number(num).toFixed(2);
			}
		},
		methods: {
			gotoGoodsDetail(e,goods) {
				uni.navigateTo({
					url: "/subpkg/goods_detail/goods_detail?goods_id="+goods.goods_id
				})
			},
			clickHandler(e) {
				this.$emit("radioChange",{
					goods_id: this.goods.goods_id,
					goods_state: this.goods.goods_state
				})
			},
			changeHandler(value) {
				this.$emit("numberChange",{
					goods_id: this.goods.goods_id,
					goods_count: value
				})
			}
		}
	}
</script>

<style lang="scss">
	
.goods-item {
	width: 750rpx;
	box-sizing: border-box;
	display: flex;
	margin: 10px 5px;
	border-bottom: 1px solid #f0f0f0;
	
	.goods-item-left {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-right: 5px;
		
		image {
			width: 100px;
			height: 100px;
		}
	}
	
	.goods-item-right {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		
		.title {
			font-size: 13px;
		}
		.priceAndNum {
			display: flex;
			align-items: center;
			justify-content: space-between;
			
			.price {
				font-size: 16px;
				color: #C00000;
			}			
		}
	}
}
</style>